package main

import (
	"database/sql"
	"fmt"
	"log"

	_ "github.com/go-sql-driver/mysql"
)

func main() {
	registerUser("longqiang", "OeSF0Q7NS277bwX5Lj-8FzLRWB-RRRZkIyMS")
	// 调用方法插入数据库
}

func registerUser(username string, password string) error {
	// Connect to the database
	db, err := sql.Open("mysql", "root:123456@tcp(127.0.0.1:3306)/my_chatgpt")
	if err != nil {
		log.Fatal(err)
	}
	defer db.Close()

	// Prepare the SQL statement
	stmt, err := db.Prepare("INSERT INTO users(username, password) VALUES(?, ?)")
	if err != nil {
		log.Fatal(err)
	}
	defer stmt.Close()

	// Execute the statement
	_, err = stmt.Exec(username, password)
	if err != nil {
		log.Fatal(err)
	}

	fmt.Println("User registered successfully")
	return nil
}
